<template>
  <div class="login-container">
    <!-- 深蓝色背景 -->
    <div class="fullscreen-bg"></div>

    <!-- 登录卡片 -->
    <div class="login-card">
      <!-- 系统标题 -->
      <div class="system-title">
        <el-icon class="loading-icon"><Loading /></el-icon>
        <h1>欢迎来到仓库系统</h1>
      </div>

      <!-- 输入表单 -->
      <div class="login-form">
        <el-input
            v-model="loginData.username"
            placeholder="请输入用户名"
            class="custom-input"
        />
        <el-input
            v-model="loginData.password"
            type="password"
            placeholder="请输入密码"
            show-password
            class="custom-input"
        />
        <el-button @click="handleLogin" type="success" class="login-btn">立即登录</el-button>
      </div>

      <!-- 其他登录方式 -->
      <div class="other-login">
        <el-divider><span class="divider-text">其它方式登录</span></el-divider>
        <div class="social-icons">
          <el-icon><Apple /></el-icon>
          <el-icon><ChatLineRound /></el-icon>
          <el-icon><Cellphone /></el-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {
  Loading,
  Apple,
  ChatLineRound,
  Cellphone
} from '@element-plus/icons-vue'
import {login} from "@/api/auth.js";
import router from "@/router/index.js";
import {ElMessage} from "element-plus";
const loginData=ref({
  username:'',
  password:''
})


const handleLogin=async ()=>{
  try {
    const res=await login(loginData.value)
    console.log(res)
    if(res.code===200){
    localStorage.setItem('token',res.data.token)
      if(res.data.role===0){

        await router.push('/')

      }else {
        await router.push('/user')
      }

    }

  }catch (error){
    ElMessage.error('账号或密码错误请重试')

  }



}

</script>

<style lang="scss" scoped>
/* 严格消除白边 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.login-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(to right,  #ce93c1ff 0.0%, #dcd2b6ff 50.0%, #7ba2d3ff 100.0%);


  /* 全屏覆盖背景 */
  .fullscreen-bg {
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    background: inherit;
    z-index: 0;
  }

  .login-card {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 380px;
    background: white;
    border-radius: 8px;
    padding: 40px 30px;
    box-shadow: 0 0 0 2px #217e12, /* 红色边框 */
    0 15px 30px rgba(0,0,0,0.2);

    .system-title {
      text-align: center;
      margin-bottom: 30px;

      .loading-icon {
        font-size: 40px;
        color: #409EFF;
        margin-bottom: 10px;
      }

      h1 {
        font-size: 22px;
        color: #333;
        letter-spacing: 2px;
      }
    }

    .custom-input {
      margin-bottom: 20px;

      :deep(.el-input__inner) {
        height: 40px;
        border-radius: 4px;
      }
    }

    .login-btn {
      width: 100%;
      height: 40px;
      font-size: 16px;
      margin-top: 15px;
    }

    .other-login {
      margin-top: 25px;

      .divider-text {
        color: #666;
        font-size: 14px;
      }

      .social-icons {
        display: flex;
        justify-content: center;
        gap: 25px;
        margin-top: 15px;

        .el-icon {
          font-size: 24px;
          color: #666;
          cursor: pointer;
        }
      }
    }
  }
}

/* 彻底隐藏所有滚动条 */
::-webkit-scrollbar {
  display: none;
}
</style>